package dome1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    public static final String[] SUITS = {"♥","♠","♦","♣"};
    public List<Card> creatCard() {
        List<Card> list =new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                Card card = new Card(suit,j);
                list.add(card);
            }
        }
        return list;
    }
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0; i--) {
            int ret = random.nextInt(i);
            swap(cardList,i,ret);
        }
    }
    private void swap(List<Card> cardList,int i,int j) {
        Card tmp = cardList.get(j);
        cardList.set(j,cardList.get(i));
        cardList.set(i,tmp);
    }
    public List<List<Card>> play(List<Card> cardList) {
        List<List<Card>> head = new ArrayList<>();
        List<Card> head0 = new ArrayList<>();
        List<Card> head1 = new ArrayList<>();
        List<Card> head2 = new ArrayList<>();
        head.add(head0);
        head.add(head1);
        head.add(head2);
        //每人揭5张牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                head.get(j).add(card);
            }
        }
        return head;
    }
}
